package com.sanyang.logistics.zhd.handler;

import java.io.UnsupportedEncodingException;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sanyang.logistics.pojo.OwnerTypeDim;
import com.sanyang.logistics.pojo.TruckDim;
import com.sanyang.logistics.zhd.service.ITruckDimService;

@Controller
@RequestMapping("/truck")
public class TruckDimHandler {


	@Autowired
	private ITruckDimService truckService;

	/**
	 * 查询全部车辆
	 * @return
	 */
	@RequestMapping("/getAllTruck")
	@ResponseBody
	public Object getAllTruck(TruckDim truckDim){
				
		

		List<TruckDim> allTruck = truckService.getAllTruck(truckDim);
		//		System.out.println(allTruck);
		return allTruck;
	}

	/**
	 * 查询车辆
	 * @return
	 */
	@RequestMapping("/getTruck")
	@ResponseBody
	public Object getTruck(TruckDim truckDim){
		//        System.out.println(truckDim.getTruck_id());
		TruckDim truck = truckService.getTruck(truckDim.getTruck_id());
		//		System.out.println(truck);
		return truck;
	}

	/**
	 * 修改车辆
	 * @return
	 */
	@RequestMapping("/updateTruck")
	@ResponseBody
	public Object updateTruck(TruckDim truckDim){
		//        System.out.println(truckDim.getTruck_id());
		truckService.updateTruck(truckDim);
		return "1";
	}

	/**
	 * 添加车辆
	 * @return
	 */
	@RequestMapping("/addTruck")
	@ResponseBody
	public Object addTruck(TruckDim truckDim){
		//        System.out.println(truckDim.getTruck_id());
		//		System.out.println(111);
		truckService.addTruck(truckDim);
		return "1";
	}


	/**
	 * 删除车辆
	 * @return
	 */
	@RequestMapping("/deleteTruck")
	@ResponseBody
	public Object deleteTruck(Integer truck_id){
		//        System.out.println(truckDim.getTruck_id());
		//		System.out.println(111);
		truckService.deleteTurck(truck_id);
		return "1";
	}

	/**
	 * 查询车牌号
	 * @return
	 */
	@RequestMapping("/getTruckLicense")
	@ResponseBody
	public Object getTruckLicense(String license){
		TruckDim truckLicense = truckService.getTruckLicense(license);
		if (truckLicense!=null) {
			return "1";
		}
		return null;
	}
	
	/**
	 * 查询车辆所有者
	 * @return
	 */
	@RequestMapping("/getAllOwnerTypeDim")
	@ResponseBody
	public Object getAllOwnerTypeDim(){
		List<OwnerTypeDim> allOwnerTypeDim = truckService.getAllOwnerTypeDim();
//		System.out.println(allOwnerTypeDim);
		return allOwnerTypeDim;
	}

}
